package ltd.dujiabao.eduvod.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import ltd.dujiabao.commonutils.Result;
import ltd.dujiabao.eduvod.service.VideoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author : DuJiabao
 * @Project : online-course-project
 * @Time : 2021/4/23 10:57
 * @Desc :
 */
@Api("阿里云视频点播微服务")
@CrossOrigin
@RestController
@RequestMapping("/eduvod/video")
@Slf4j
public class VideoController {
  @Autowired
  VideoService videoService;

  @ApiOperation("上传视频")
  @PostMapping("/upload")
  public Result uploadVideo(MultipartFile file) {
    String videoId = videoService.uploadVideo(file);
    log.info("上传视频成功，id为 "+ videoId);
    return Result.success().addData("videoId", videoId);
  }

  @ApiOperation("删除视频")
  @DeleteMapping("/{videoId}")
  public Result removeVideo(@PathVariable("videoId") String videoId) {
    boolean isSuccess = videoService.removeVideo(videoId);
    if (isSuccess) {
      log.info("删除视频成功，id为 "+ videoId);
      return Result.success();
    } else {
      log.error("删除视频失败，id为 "+ videoId);
      return Result.failure();
    }
  }
}
